home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / sendsigs < prev    next >
Text File  |  2008-10-14  |  2KB  |  97 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          sendsigs
  4. # Required-Start:    
  5. # Required-Stop:     umountnfs
  6. # Default-Start:
  7. # Default-Stop:      0 6
  8. # Short-Description: Kill all remaining processes.
  9. # Description: 
  10. ### END INIT INFO
  11.  
  12. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  13.  
  14. . /lib/lsb/init-functions
  15.  
  16. do_stop () {
  17.     OMITPIDS=
  18.  
  19.     # The /var/run/sendsigs.omit file is used to be compatible
  20.     # with Ubuntu.
  21.     for omitfile in /var/run/sendsigs.omit /lib/init/rw/sendsigs.omit; do
  22.         if [ -e $omitfile ]; then
  23.             for pid in $(cat $omitfile); do
  24.                 OMITPIDS="${OMITPIDS:+$OMITPIDS }-o $pid"
  25.             done
  26.         fi
  27.     done
  28.  
  29.     # Load sendsigs.omit.d/packagename files too, to make it
  30.     # possible for scripts that need to modify the list of pids at
  31.     # run time without race conditions.
  32.     if [ -d /lib/init/rw/sendsigs.omit.d/ ]; then
  33.         for pidfile in /lib/init/rw/sendsigs.omit.d/*; do
  34.             [ -f "$pidfile" ] || continue
  35.             for pid in $(cat $pidfile); do
  36.                 OMITPIDS="${OMITPIDS:+$OMITPIDS }-o $pid"
  37.             done
  38.         done
  39.     fi
  40.  
  41.     # Flush the kernel I/O buffer before we start to kill
  42.     # processes, to make sure the IO of already stopped services to
  43.     # not slow down the remaining processes to a point where they
  44.     # are accidentily killed with SIGKILL because they did not
  45.     # manage to shut down in time.
  46.     sync
  47.  
  48.     # Kill all processes.
  49.     log_action_begin_msg "Asking all remaining processes to terminate"
  50.     killall5 -15 $OMITPIDS # SIGTERM
  51.     log_action_end_msg 0
  52.     alldead=""
  53.     for seq in 1 2 3 4 5 6 7 8 9 10; do
  54.         # use SIGCONT/signal 18 to check if there are
  55.         # processes left.  No need to check the exit code
  56.         # value, because either killall5 work and it make
  57.         # sense to wait for processes to die, or it fail and
  58.         # there is nothing to wait for.
  59.         
  60.         if killall5 -18 $OMITPIDS ; then
  61.             :
  62.         else
  63.             alldead=1
  64.             break
  65.         fi
  66.  
  67.         sleep 1
  68.     done
  69.     if [ -z "$alldead" ] ; then
  70.         log_action_begin_msg "Killing all remaining processes"
  71.         killall5 -9 $OMITPIDS # SIGKILL
  72.         log_action_end_msg 1
  73.     else
  74.         log_action_begin_msg "All processes ended within $seq seconds."
  75.         log_action_end_msg 0
  76.     fi
  77. }
  78.  
  79. case "$1" in
  80.   start)
  81.     # No-op
  82.     ;;
  83.   restart|reload|force-reload)
  84.     echo "Error: argument '$1' not supported" >&2
  85.     exit 3
  86.     ;;
  87.   stop)
  88.     do_stop
  89.     ;;
  90.   *)
  91.     echo "Usage: $0 start|stop" >&2
  92.     exit 3
  93.     ;;
  94. esac
  95.  
  96. :
  97.